package com.dotstone.chipism.activity;

import java.util.ArrayList;
import java.util.List;

import com.dotstone.chipism.R;
import com.dotstone.chipism.bean.Device;
import com.dotstone.chipism.bean.DeviceType;
import com.dotstone.chipism.bean.Key;
import com.dotstone.chipism.dialog.SVProgressHUD;
import com.dotstone.chipism.timepicker.AbstractWheelTextAdapter;
import com.dotstone.chipism.timepicker.OnWheelChangedListener;
import com.dotstone.chipism.timepicker.OnWheelScrollListener;
import com.dotstone.chipism.timepicker.WheelView;
import com.dotstone.chipism.util.ConvertUtil;
import com.dotstone.chipism.util.DeviceManager;
import com.dotstone.chipism.util.Util;
import com.dotstone.chipism.view.BlurBehind;
import com.dotstone.chipism.view.slidingfragmenu.BarUtils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MessionEditActivity extends BaseActivity {
	private TextView tv_statusBar_mian;
	private LinearLayout mBackL;
	private Button mNextB;
	private Button mCancelB;
	private WheelView wvDevice;
	private WheelView wvMession;
	private WheelView wvHour;
	private WheelView wvMin;
	private WheelView wvSec;
	private String selectDevice = "未知设备";
	private String selectMession = "开";
	private String selectHour = "0";
	private String selectMin = "0";
	private String selectSec = "0";
	private List<Device> mDevices = new ArrayList<Device>();
	private ArrayList<String> arry_devices = new ArrayList<String>();
	// private List<Device> arry_devices1 = new ArrayList<Device>();
	private ArrayList<String> arry_messions = new ArrayList<String>();
	private ArrayList<String> arry_hours = new ArrayList<String>();
	private ArrayList<String> arrr_mins = new ArrayList<String>();
	private ArrayList<String> arrr_secs = new ArrayList<String>();
	private CalendarTextAdapter mDeviceAdapter;
	// private CalendarTextAdapter1 mDeviceAdapter;
	private CalendarTextAdapter mMessionAdapter;
	private CalendarTextAdapter mHourdapter;
	private CalendarTextAdapter mMindapter;
	private CalendarTextAdapter mSecdapter;
	private int maxTextSize = 16;
	private int minTextSize = 16;
	private int type;
	private SVProgressHUD mSvprogressBar;
	@Override
	public void widgetClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.cancel_btn:
			setResult(999);
			finish();
			break;
		case R.id.nextstep:
			String deviceId = "";
			String address = "";
			String cmd = "";

			for (int i = 0; i < mDevices.size(); i++) {
				if (selectDevice.contains(mDevices.get(i).getDeviceName())) {
					deviceId = mDevices.get(i).getDeviceID();
					if (mDevices.get(i).getDeviceAddress() != null) {
						address = mDevices.get(i).getDeviceAddress();
					} else {
						address = mDevices.get(i).getDeviceBrand();
					}
					type = mDevices.get(i).getDeviceType();
					break;
				}
			}
			Log.i("wmy", "type = " + type + " deviceId = " + deviceId);
			if (!deviceId.equals("")) {
				byte[] data;
				byte[] data2;
				int[] dataCmd;
				switch (type) {
					case DeviceType.DEVICE_TYPE_CHAZUO://墙壁插座
				case DeviceType.DEVICE_TYPE_SOCKET://转接插座
					if (selectMession.equals("开")) {// 开
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0xff, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					} else { // 关
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0x00, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					}
					break;
				case DeviceType.DEVICE_TYPE_RGB_LIGHT:
					if (selectMession.equals("开")) {// 开
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x79, (byte) 0xff, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					} else { // 关
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x78, (byte) 0x00, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					}
					break;
				case DeviceType.DEVICE_TYPE_SWITCH:
					if (selectMession.equals("开")) {// 开
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0xff, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					} else { // 关
						data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0x00, 0x00, 0x00 };
						data2 = getPowerData(data, address);
						dataCmd = byte2HexStr(data2);
						cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
					}
					break;
					case DeviceType.DEVICE_TYPE_CURTAIN://窗帘
						if (selectMession.equals("开")) {// 开
							data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11, 0x02, 0x00, 0x00};
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
                             System.out.print("xxx");
						} else { // 关
							data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11, (byte) 0x01, 0x00, 0x00 };
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
						}
						break;
					case DeviceType.LINGHUO_SWITCH_1:
						if (selectMession.equals("开")) {// 开
							data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x12,(byte)0xff, 0x00, 0x00};
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							System.out.print("xxx");
						} else { // 关
							data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x12, (byte)00, 0x00, 0x00};
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
						}
						break;
					case DeviceType.LINGHUO_SWITCH_2:
						if(((selectDevice.substring(4,10)+selectDevice.substring(14,18)).equals("(零火2位)(1键)"))){
							if (selectMession.equals("开")) {// 开
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11,(byte)0xff, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
								System.out.print("xxx");
							} else { // 关
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11, (byte)00, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							}
						}else if(((selectDevice.substring(4,10)+selectDevice.substring(14,18)).equals("(零火2位)(2键)"))){
							if (selectMession.equals("开")) {// 开
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x13,(byte)0xff, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
								System.out.print("xxx");
							} else { // 关
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x13, (byte)00, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							}
						}
						break;
					case DeviceType.LINGHUO_SWITCH_3:
						if(((selectDevice.substring(4,10)+selectDevice.substring(14,18)).equals("(零火3位)(1键)"))){
							if (selectMession.equals("开")) {// 开
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11,(byte)0xff, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
								System.out.print("xxx");
							} else { // 关
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x11, (byte)00, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							}
						}else if(((selectDevice.substring(4,10)+selectDevice.substring(14,18)).equals("(零火3位)(2键)"))){
							if (selectMession.equals("开")) {// 开
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x12,(byte)0xff, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
								System.out.print("xxx");
							} else { // 关
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x12, (byte)00, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							}
						}else if(((selectDevice.substring(4,10)+selectDevice.substring(14,18)).equals("(零火3位)(3键)"))){
							if (selectMession.equals("开")) {// 开
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x13,(byte)0xff, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
								System.out.print("xxx");
							} else { // 关
								data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x13, (byte)00, 0x00, 0x00};
								data2 = getPowerData(data, address);
								dataCmd = byte2HexStr(data2);
								cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							}
						}

					/*	if (selectMession.equals("开")) {// 开
							data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10,(byte)0xff, 0x00, 0x00};
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							System.out.print("xxx");
						} else { // 关
							data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0x00, 0x00, 0x00 };
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
						}*/
						break;
					case DeviceType.DANHUO_SWITCH_1:
					case DeviceType.DANHUO_SWITCH_2:
					case DeviceType.DANHUO_SWITCH_3:
						if (selectMession.equals("开")) {// 开
							data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10,(byte)0xff, 0x00, 0x00};
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
							System.out.print("xxx");
						} else { // 关
							data = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x10, (byte) 0x00, 0x00, 0x00 };
							data2 = getPowerData(data, address);
							dataCmd = byte2HexStr(data2);
							cmd = ConvertUtil.getInstance().convertMessionCmd(dataCmd, deviceId);
						}
						break;
				case DeviceType.DEVICE_TYPE_AIR_CONTROLLER:
				case DeviceType.DEVICE_TYPE_BOX2:
				case DeviceType.DEVICE_TYPE_DVD:
				case DeviceType.DEVICE_TYPE_FAN:
				case DeviceType.DEVICE_TYPE_PROJECTOR:
				case DeviceType.DEVICE_TYPE_TV:
					Log.i("wmy", "任务的设备类型是遥控器");
					if (selectMession.equals("开")) {// 开
						List<Key> keys = DeviceManager.getInstance().getDeviceById(deviceId).getKeys();
						for (int i = 0; i < keys.size(); i++) {
							if (keys.get(i).getKeyNum() == 800) {
								cmd = ConvertUtil.getInstance().convertIrCmd(keys.get(i).getCodeValue());
								Log.i("wmy", "获取指令 = " + cmd);
							}
						}
					} else { // 关
						List<Key> keys = DeviceManager.getInstance().getDeviceById(deviceId).getKeys();
						boolean e = false;
						for (int i = 0; i < keys.size(); i++) {
							if (keys.get(i).getKeyNum() == 4000) {
								e = true;
								cmd = ConvertUtil.getInstance().convertIrCmd(keys.get(i).getCodeValue());
								Log.i("wmy", "获取指令 = " + cmd);
							}
						}
						if (!e) {
							for (int i = 0; i < keys.size(); i++) {
								if (keys.get(i).getKeyNum() == 800) {
									e = true;
									cmd = ConvertUtil.getInstance().convertIrCmd(keys.get(i).getCodeValue());
									Log.i("wmy", "获取指令 = " + cmd);
								}
							}
						}
					}
					break;
				default:
					break;
				}
			}
			Intent intent = new Intent();
			intent.putExtra("device", selectDevice);
			intent.putExtra("deviceId", deviceId);
			intent.putExtra("cmd", cmd);
			intent.putExtra("mession", selectMession+"|"+selectDevice);
			intent.putExtra("hour", selectHour);
			intent.putExtra("minute", selectMin);
			intent.putExtra("second", selectSec);
			setResult(0, intent);
			finish();
			break;

		default:
			break;
		}
	}
	
	@SuppressLint("HandlerLeak")
	Handler mHandler = new Handler(){
		public void handleMessage(Message msg){
			switch (msg.what) {
			case 0:
				if(mSvprogressBar.isShowing()){
					mSvprogressBar.dismiss();
				}
				setTextviewSize(arry_devices.get(0),mDeviceAdapter);
				setTextviewSize(arry_messions.get(0),mMessionAdapter);
				break;

			default:
				break;
			}
		}
	};

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			setResult(999);
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void initParms(Bundle parms) {
		// TODO Auto-generated method stub

	}

	@Override
	public View bindView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_mession_edit;
	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		BlurBehind.getInstance()
				// .withAlpha(80)
				// .withFilterColor(Color.parseColor("#000000"))
				.setBackground(this);
		tv_statusBar_mian = $(R.id.tv_statusBar_mian);
		mBackL = $(R.id.back_layout);
		mBackL.setVisibility(View.GONE);
		mNextB = $(R.id.nextstep);
		mNextB.setText(getString(R.string.ok));
		mNextB.setVisibility(View.VISIBLE);
		mCancelB = $(R.id.cancel_btn);
		boolVersion();
		wvDevice = $(R.id.wv_device);
		wvMession = $(R.id.wv_mession);
		wvHour = $(R.id.wv_hour);
		wvMin = $(R.id.wv_minute);
		wvSec = $(R.id.wv_second);
		mNextB.setOnClickListener(this);
		mCancelB.setOnClickListener(this);
		mSvprogressBar = new SVProgressHUD(MessionEditActivity.this);
		mSvprogressBar.showWithStatus("正在加载");
		initData();
//		mHandler.postDelayed(new Runnable() {
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				mHandler.sendEmptyMessage(0);
//			}
//		}, 1000);
	}

	private void initData() {
		// TODO Auto-generated method stub
		mDevices = DeviceManager.getInstance().getNoLockDevice();
		// mDevices = DeviceManager.getInstance().getMessionDevice();
		for (int i = 0; i < mDevices.size(); i++) {
			if(mDevices.get(i).getDeviceName().contains("无线开关")){

			}else if(mDevices.get(i).getDeviceType()==7){//摄像头

			}else if(mDevices.get(i).getDeviceType()==98){
				Log.e(""," "+mDevices.get(i).getDeviceType());
				arry_devices.add(mDevices.get(i).getDeviceName()+"(1键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(2键)");
			}else if(mDevices.get(i).getDeviceType()==99){
				arry_devices.add(mDevices.get(i).getDeviceName()+"(1键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(2键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(3键)");
			}else if(mDevices.get(i).getDeviceType()==101){
				arry_devices.add(mDevices.get(i).getDeviceName()+"(1键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(2键)");
			}else if(mDevices.get(i).getDeviceType()==102){
				arry_devices.add(mDevices.get(i).getDeviceName()+"(1键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(2键)");
				arry_devices.add(mDevices.get(i).getDeviceName()+"(3键)");
			}else{
				arry_devices.add(mDevices.get(i).getDeviceName());
			}
			// Log.i("wmy", "共有arry_devices1.size() = " + arry_devices.size());
		}
		if (arry_devices.size() != 0) {
			selectDevice = arry_devices.get(0);
		}
		arry_messions.add("开");
		arry_messions.add("关");
		for (int i = 0; i <= 23; i++) {
			arry_hours.add(i + "");
		}
		for (int i = 0; i < 60; i++) {
			arrr_mins.add(i + "");
		}
		for (int i = 0; i < 60; i++) {
			arrr_secs.add(i + "");
		}
		mDeviceAdapter = new CalendarTextAdapter(getApplicationContext(), arry_devices, 0,
				maxTextSize, minTextSize);
		wvDevice.setVisibleItems(4);
		wvDevice.setViewAdapter(mDeviceAdapter);
		wvDevice.setCurrentItem(0);
//		Log.i("wmy", "275 设置字体颜色"+arry_devices.get(0));
//		setTextviewSize(arry_devices.get(0),mDeviceAdapter);
		mMessionAdapter = new CalendarTextAdapter(getApplicationContext(), arry_messions, 0,
				maxTextSize, minTextSize);
		wvMession.setVisibleItems(4);
		wvMession.setViewAdapter(mMessionAdapter);
		wvMession.setCurrentItem(0);
//		Log.i("wmy", "282 设置字体颜色"+arry_messions.get(0));
//		setTextviewSize(arry_messions.get(0),mMessionAdapter);
		mHourdapter = new CalendarTextAdapter(getApplicationContext(), arry_hours, arry_hours.size(), maxTextSize,
				minTextSize);
		wvHour.setVisibleItems(4);
		wvHour.setViewAdapter(mHourdapter);
		wvHour.setCurrentItem(0);

		mMindapter = new CalendarTextAdapter(getApplicationContext(), arrr_mins, arrr_mins.size(), maxTextSize,
				minTextSize);
		wvMin.setVisibleItems(4);
		wvMin.setViewAdapter(mMindapter);
		wvMin.setCurrentItem(0);

		mSecdapter = new CalendarTextAdapter(getApplicationContext(), arrr_secs, arrr_secs.size(), maxTextSize,
				minTextSize);
		wvSec.setVisibleItems(4);
		wvSec.setViewAdapter(mSecdapter);
		wvSec.setCurrentItem(0);

		wvDevice.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				String currentText = (String) mDeviceAdapter.getItemText(wheel.getCurrentItem());
				selectDevice = currentText;
				setTextviewSize(currentText, mDeviceAdapter);
			}
		});

		wvDevice.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				String currentText = (String) mDeviceAdapter.getItemText(wheel.getCurrentItem());
				setTextviewSize(currentText, mDeviceAdapter);
			}
		});

		wvMession.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				String currentText = (String) mMessionAdapter.getItemText(wheel.getCurrentItem());
				selectMession = currentText;
				setTextviewSize(currentText, mMessionAdapter);
			}
		});

		wvMession.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				String currentText = (String) mMessionAdapter.getItemText(wheel.getCurrentItem());
				setTextviewSize(currentText, mMessionAdapter);
			}
		});

		wvHour.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				String currentText = (String) mHourdapter.getItemText(wheel.getCurrentItem());
				selectHour = currentText;
				setTextviewSize(currentText, mHourdapter);
			}
		});

		wvHour.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				String currentText = (String) mHourdapter.getItemText(wheel.getCurrentItem());
				setTextviewSize(currentText, mHourdapter);
			}
		});

		wvMin.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				String currentText = (String) mMindapter.getItemText(wheel.getCurrentItem());
				selectMin = currentText;
				setTextviewSize(currentText, mMindapter);
				// current = Integer.parseInt(currentText);
				// setYear(currentYear);
				// initMonths(month);
				// mMonthAdapter = new CalendarTextAdapter(
				// getApplicationContext(), arry_months, 0, maxTextSize,
				// minTextSize);
				// wvMonth.setVisibleItems(5);
				// wvMonth.setViewAdapter(mMonthAdapter);
				// wvMonth.setCurrentItem(0);
			}
		});

		wvMin.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				String currentText = (String) mMindapter.getItemText(wheel.getCurrentItem());
				setTextviewSize(currentText, mMindapter);
			}
		});

		wvSec.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				// TODO Auto-generated method stub
				String currentText = (String) mSecdapter.getItemText(wheel.getCurrentItem());
				selectSec = currentText;
				setTextviewSize(currentText, mSecdapter);
				// current = Integer.parseInt(currentText);
				// setYear(currentYear);
				// initMonths(month);
				// mMonthAdapter = new CalendarTextAdapter(
				// getApplicationContext(), arry_months, 0, maxTextSize,
				// minTextSize);
				// wvMonth.setVisibleItems(5);
				// wvMonth.setViewAdapter(mMonthAdapter);
				// wvMonth.setCurrentItem(0);
			}
		});

		wvSec.addScrollingListener(new OnWheelScrollListener() {

			@Override
			public void onScrollingStarted(WheelView wheel) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onScrollingFinished(WheelView wheel) {
				// TODO Auto-generated method stub
				String currentText = (String) mSecdapter.getItemText(wheel.getCurrentItem());
				setTextviewSize(currentText, mSecdapter);
			}
		});
		mHandler.sendEmptyMessage(0);
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doBusiness(Context mContext) {
		// TODO Auto-generated method stub

	}

	private class CalendarTextAdapter extends AbstractWheelTextAdapter {
		ArrayList<String> list;

		protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize,
				int minsize) {
			super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize,0);
			this.list = list;
			setItemTextResource(R.id.tempValue);
		}

		@Override
		public View getItem(int index, View cachedView, ViewGroup parent) {
			View view = super.getItem(index, cachedView, parent);
			return view;
		}

		@Override
		public int getItemsCount() {
			return list.size();
		}

		@Override
		protected CharSequence getItemText(int index) {
			return list.get(index) + "";
		}
	}

	public void boolVersion() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			// getWindow().addFlags(
			// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			// 改变titlebar的高度
			int statusbarHeight = BarUtils.getStatusBarHeight(this);
			RelativeLayout.LayoutParams layoutParams1 = (RelativeLayout.LayoutParams) tv_statusBar_mian
					.getLayoutParams();
			layoutParams1.height = statusbarHeight;
			tv_statusBar_mian.setLayoutParams(layoutParams1);
			tv_statusBar_mian.setVisibility(View.VISIBLE);

		} else {
			tv_statusBar_mian.setVisibility(View.GONE);
		}
	}

	public void setTextviewSize(String curriteItemText, CalendarTextAdapter adapter) {
		ArrayList<View> arrayList = adapter.getTestViews();
		int size = arrayList.size();
		String currentText;
		Log.i("wmy", "548 curriteItemText = "+curriteItemText+" "+size);
		for (int i = 0; i < size; i++) {
			TextView textvew = (TextView) arrayList.get(i);
			currentText = textvew.getText().toString();
			if (curriteItemText.equals(currentText)) {
				textvew.setTextSize(maxTextSize);
				// currentPosition = i;
				textvew.setTextColor(Color.parseColor("#ffffff"));
				Log.e("wmy", "设置为白色"+curriteItemText);
			} else {
				textvew.setTextSize(minTextSize);
				textvew.setTextColor(Color.parseColor("#4dffffff"));
				Log.i("wmy", "设置为灰色"+curriteItemText);
			}
		}
	}

	public byte[] getPowerData(byte[] commandData, String deviceAddress) {
		int CMDLENGTH = 10;
		byte[] deviceAdd = Util.hexStringToBytes(deviceAddress);
		byte[] cmdData = new byte[CMDLENGTH];
		System.arraycopy(commandData, 0, cmdData, 0, CMDLENGTH);
		System.arraycopy(deviceAdd, 0, cmdData, 1, 5);
		return cmdData;
	}

	public static int[] byte2HexStr(byte[] b) {
		int[] cmd = new int[b.length];
		String stmp = "";
		StringBuilder sb = new StringBuilder("");
		for (int n = 0; n < b.length; n++) {
			stmp = Integer.toHexString(b[n] & 0xFF);
			sb.append((stmp.length() == 1) ? stmp : stmp);
			sb.append(",");
			cmd[n] = Integer.parseInt(stmp, 16);
		}
		return cmd;
	}

}
